
import axios from 'axios';
import { getToken } from '../utils/auth';
import { Message } from '@garco-design/web-vue'
// 所有项目列表
const caRequest = axios.create({
    baseURL: '/api/auth',
    timeout: 60000,
  });
  // 请求拦截器
  caRequest.interceptors.request.use(
    (config) => {
      const token = getToken();
      if (token) {
        config.headers.Authorization = `Bearer ${token}`;
      }
      // 判断参数是否为空
      if (config.method === "get") {
        const query = config.params;
        for (const key in query) {
          if (!query[key]) {
            delete query[key];
          }
        }
      }
      return config;
    },
    (error) => {
      return Promise.reject(error);
    }
  );
  // 响应拦截器
  caRequest.interceptors.response.use(
    function (response) {
      const res = response.data;
      if (res.code !== 200 && res.code !== 20000) Message.error(res.message || res.description);
      return res;
    },
  );

  export function commonArchTree(params: any) {
    return caRequest({
      url: `/system/arch/tree/`,
      method: 'get',
      params,
    });
  }